#include "Book.h"


Book::Book(void)
{
	this->type = "Book";
	this->year = 0;
	this->pages = 0;
}

Book::Book( string title, string author, string genre, int year, int pages )
{
	this->type = "Book";
	this->title = title;
	this->author = author;
	this->genre = genre;
	this->year = year;
	this->pages = pages;
}


Book::~Book(void)
{
}

void Book::Print( ostream &out )
{
	out << *this;
}


ostream &operator<<( ostream &out, const Book &book )
{
	out << "(";
	out << book.type << ",";
	out << book.title << ",";
	out << book.author << ",";
	out << book.genre << ",";
	out << book.year << ",";
	out << book.pages;
	out << ")" << endl;
	return out;
}


istream &operator>>( istream &in, Book &book )
{
	char c;
	book.type = "Book";
	in >> skipws;
	std::getline( in, book.title, ',' );
	in >> skipws;
	std::getline (in, book.author, ',' );
	in >> skipws;
	std::getline( in, book.genre, ',' );
	in >> skipws;
	in >> book.year;
	in >> skipws;
	in >> c >> skipws;
	in>> book.pages;
	in >> skipws >> c;

	return in;
}

bool operator==( const Book &one, const Book &other )
{
	if( one.title == other.title )
	{
		if( one.author == other.author )
		{
			if( one.genre == other.genre )
			{
				if( one.year == other.year )
				{
					if( one.pages == other.pages )
					{
						return true;
					}
				}
			}
		}
	}
	return false;
}

bool operator!=( const Book &one, const Book &other )
{
	return !( one == other );
}

bool operator<( const Book &one, const Book &other )
{

	if( (one.author < other.author) )
		return true;
	else if( ( (one.author == other.author) ) && (one.year < other.year) )
		return true;
	else if( ( ((one.author == other.author) ) && (one.year == other.year) ) && (one.genre < other.genre) )
		return true;
	else if( ( (((one.author == other.author) ) && (one.year == other.year) ) && (one.genre == other.genre) ) &&  (one.title < other.title) )
		return true;
	else if( ( ((((one.author == other.author) ) && (one.year == other.year) ) && (one.genre == other.genre) ) &&  (one.title == other.title) ) && (one.pages > other.pages) )
		return true;
	else
		return false;
}

bool Book::sort_pred( Book one, Book other )
{
	if( (one.author < other.author) )
		return true;
	else if( ( (one.author == other.author) ) && (one.year < other.year) )
		return true;
	else if( ( ((one.author == other.author) ) && (one.year == other.year) ) && (one.genre < other.genre) )
		return true;
	else if( ( (((one.author == other.author) ) && (one.year == other.year) ) && (one.genre == other.genre) ) &&  (one.title < other.title) )
		return true;
	else if( ( ((((one.author == other.author) ) && (one.year == other.year) ) && (one.genre == other.genre) ) &&  (one.title == other.title) ) && (one.pages > other.pages) )
		return true;
	else
		return false;
}